﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SGGWElevator
{
    /// <summary>
    /// Helper, generetes unique IDs basic on Random.
    /// Author: Paweł Iżycki
    /// </summary>
    public class UniqueIdGenerator
    {
        static Random random;

        /// <summary>
        /// Table conaining all used IDs.
        /// </summary>
        static List<int> IdList = new List<int>();

        /// <summary>
        /// Generates new unique ID.
        /// </summary>
        /// <param name="idTable"></param>
        /// <returns>Unique ID</returns>
        public static int GetUniqueId()
        {
            lock (random = new Random())
            {
                int uniqueId;
                do
                {
                    uniqueId = random.Next(Int32.MaxValue - 32);
                } while (IdList.Contains(uniqueId));

                IdList.Add(uniqueId);

                return uniqueId;
            }
        }
    }
}
